module.factory('UpdateInsertDB', function ($http) {
    var promise;
    var PostData = {
        async: function (jsondata) {
            //if (!promise) {
            var req = {
                method: 'POST',
                url: '/opMetaInfo/update',
                headers: {
                    'Content-Type': 'application/json'
                },
                data: jsondata
            };
            promise = $http(req).then(function (response) {
                if( response&& response.data ){
                    var result = response.data;
                    if( result.ret ){
                        return result ;
                    }
                    console.log("[INFO][service.js]opMetaInfo updating failed.") ;
                    throw result ;
                }
                return response;
            });
            //}
            return promise;
        }
    };
    return PostData;
});

module.factory('DeleteImageData', function ($http,registryVersion) {
    var promise;
    var PostData = {
        async: function (name,tag) {
            var urlPrefix = '/api/deleteRepo?id=' ;

            if(registryVersion && registryVersion.deleteRepo){
                urlPrefix = registryVersion.deleteRepo ;
            }
            var req = {
                method: 'DELETE',
                //
                url:urlPrefix + encodeURIComponent(name)+'&tag='+tag,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                }
            };
            promise = $http(req).then(function (response) {
                return response;
            });

            return promise;
        }
    };
    return PostData;
});

module.factory('PublishImageData', function ($http) {
    var promise;
    var PostData = {
        async: function (jsondata) {
            //if (!promise) {
                var req = {
                    method: 'POST',
                    //
                    url: '/apiDocker/publishImg',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    data: jsondata
                };
                promise = $http(req).then(function (response) {
                    return response;
                });
            //}
            return promise;
        }
    };
    return PostData;
});